<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------
namespace app\plat\model;

/**
 * 用户模型
 */
class TenUser extends PlatBase
{
    /**
     * 获取用户部门职位角色信息，特别菜单
     * @param $userId
     * @return array[]
     * @author: 开发人生 goodkfrs@qq.com
     * @Time: 2025/3/9 17:07
     */
    public function getTenUserDeptPositionRole($userId = 0)
    {
        $rtnArray = [
            'dept_list' => [],
            'position_list' => [],
            'role_list' => []
        ];
        $this->modelTenUserDept->alias('a');
        $this->modelTenUserDept->join = [
            ['ten_dept b', 'a.ten_dept_id=b.id'],
        ];
        $where['a.ten_user_id'] = $userId;
        $rtnArray['dept_list'] = $this->modelTenUserDept->getList($where, 'a.ten_dept_id,b.*', '', false)->toArray();

        $this->modelTenUserPosition->alias('a');
        $this->modelTenUserPosition->join = [
            ['ten_position b', 'a.ten_position_id=b.id'],
        ];
        $where['a.ten_user_id'] = $userId;
        $rtnArray['position_list'] = $this->modelTenUserPosition->getList($where, 'a.ten_position_id,b.*', '', false)->toArray();

        $this->modelTenUserRole->alias('a');
        $this->modelTenUserRole->join = [
            ['ten_role b', 'a.ten_role_id=b.id'],
        ];
        $where['a.ten_user_id'] = $userId;
        $rtnArray['role_list'] = $this->modelTenUserRole->getList($where, 'a.ten_role_id,b.*', '', false)->toArray();

        $this->modelTenUserMenu->alias('a');
        $this->modelTenUserMenu->join = [
            ['ten_menu b', 'a.ten_user_id=b.id'],
        ];
        $where['a.ten_user_id'] = $userId;
        $rtnArray['menu_list'] = $this->modelTenUserMenu->getList($where, 'a.ten_menu_id,b.*', '', false)->toArray();
        return $rtnArray;
    }


    /**
     * 获取部门下所有用户
     * @param $deptIds
     * @param $positionIds
     * @return mixed
     * @author: 开发人生 goodkfrs@qq.com
     * @Time: 2025/3/18 14:28
     */
    public function getTenUserLink($deptIds = [], $positionIds = [])
    {
        $this->modelTenUserDept->alias('a');
        $this->modelTenUserDept->join = [
            [SYS_DB_PREFIX . 'ten_user b', 'a.ten_user_id=b.id'],
            [SYS_DB_PREFIX . 'ten_user_position p', 'a.ten_user_id=p.ten_user_id'],
        ];
        $where['a.ten_dept_id'] = ['in', $deptIds];
        $where['p.ten_position_id'] = ['in', $positionIds];
        $userList = $this->modelTenUserDept->getList($where, 'b.*', 'a.id desc', false)->toArray();
        return $userList;
    }

}
